﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;

public partial class _Default : Page
{

  
    protected void Page_Load(object sender, EventArgs e)
    {
    }


    protected void btnSend_Click(object sender, EventArgs e)
    {
        string query = "INSERT INTO `mensajes` (`id`, `de`, `para`, `contenido`) VALUES (1, '"+txtDe.Text+"', '"+txtPara.Text+"', '"+mensaje.Text+"')";
        MySqlConnection myConnection = new MySqlConnection();
        myConnection.ConnectionString = "Persist Security Info=False;Username=root;Password=;database=dad;server=localhost;Connect Timeout=30";
        myConnection.Open();

        //create command and assign the query and connection from the constructor
        MySqlCommand cmd = new MySqlCommand(query, myConnection);
        //Execute command
        cmd.ExecuteNonQuery();
        //close connection
        myConnection.Close();
        Type cstype = this.GetType();
        // Get a ClientScriptManager reference from the Page class.
        ClientScriptManager cs = Page.ClientScript;

        // Check to see if the startup script is already registered.
        if (!cs.IsStartupScriptRegistered(cstype, "PopupScript"))
        {
            String cstext = "alert('Mensaje enviado');";
            cs.RegisterStartupScript(cstype, "PopupScript", cstext, true);
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        txtDe.Text = "";
        txtPara.Text = "";
        mensaje.Text = "";
    }
}